# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Josip Ponjavic <josipponjavic at gmail dot com>
# Contributor: Xu Fasheng <fasheng.xu[AT]gmail.com>

pkgname=golang-github-linuxdeepin-go-dbus-factory
pkgver=1.11.2
pkgrel=1
pkgdesc='GO DBus factory for DDE'
arch=('any')
url="https://github.com/linuxdeepin/go-dbus-factory"
license=('GPL3')
depends=('golang-deepin-lib' 'golang-github-fsnotify-fsnotify' 'golang-gopkg-yaml.v3')
makedepends=('go' 'git')
checkdepends=('golang-github-stretchr-testify')
provides=('deepin-go-dbus-factory')
conflicts=('deepin-go-dbus-factory')
replaces=('deepin-go-dbus-factory')
source=("$pkgname-$pkgver.tar.gz::https://github.com/linuxdeepin/go-dbus-factory/archive/$pkgver.tar.gz")
sha512sums=('1b69fae1cad902d26deadb4a7396cabd1db19b227b94b1ca956422bb7dc7ad0587d3b39822052a6e34b49df32b062728c0e23670297121e25a225403bbeb31e6')

export GO111MODULE=off

prepare() {
  export GOPATH="$srcdir/build:/usr/share/gocode"
  mkdir -p "$srcdir"/build/src/github.com/linuxdeepin
  cp -a "$srcdir"/go-dbus-factory-$pkgver "$srcdir"/build/src/github.com/linuxdeepin/go-dbus-factory

  go get github.com/godbus/dbus
}

build() {
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  export CGO_LDFLAGS="${LDFLAGS}"
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"

  cd "$srcdir"/build/src/github.com/linuxdeepin/go-dbus-factory
  make bin

  # Suggested by upstream: don't run
  # ./gen.sh
}

check() {
  export GOPATH="$srcdir/build:/usr/share/gocode"
  cd "$srcdir"/build/src/github.com/linuxdeepin/go-dbus-factory
  go test -v $(go list ./...)
}

package() {
  cd "$srcdir"/build/src/github.com/linuxdeepin/go-dbus-factory
  install -dm755 "$pkgdir"/usr/share/gocode/src/github.com/linuxdeepin/go-dbus-factory
  cp -a com.* org.* net.* object_manager "$pkgdir"/usr/share/gocode/src/github.com/linuxdeepin/go-dbus-factory/
}
